package services

import (
	"colly/models"
	"gorm.io/gorm"
	"net/http"
)

func ListCookie(db *gorm.DB) map[string][]*http.Cookie {
	cookies := make([]models.Cookie, 0)
	db.Where("enable = ? ", 1).Find(&cookies)
	cookieMap := make(map[string][]*http.Cookie)
	for _, cookie := range cookies {
		email := cookie.Email
		if _, ok := cookieMap[email]; !ok {
			cookieMap[email] = make([]*http.Cookie, 0)
		}
		cookieMap[email] = append(cookieMap[email], cookie.Cookies())
	}
	return cookieMap
}
